package com.xfly.app.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.ptmall.app.R;
import com.ptmall.app.base.BaseMvpActivity;
import com.ptmall.app.net.api.ApiDataRepository;
import com.ptmall.app.net.base.ApiNetResponse;
import com.ptmall.app.view.TitleBarView;
import com.xfly.app.adapter.HtAdapter;
import com.xfly.app.bean.HtBean;
import com.xfly.app.bean.KcBean;

import java.util.List;

public class HtActivity extends BaseMvpActivity{

    ApiDataRepository apiDataRepository = ApiDataRepository.getInstance();
    HtAdapter htAdapter;
    ListView listView;
    TitleBarView titleBarView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setView(R.layout.activity_list2);
    }

    @Override
    public void initViews() {
        titleBarView = findViewById(R.id.titlebar);
        listView = findViewById(R.id.listview);

        titleBarView.setText("合同管理");
    }

    @Override
    public void initEvents() {
        titleBarView.setOnTitleBarClickListener(new TitleBarView.TitleBarClickListener() {
            @Override
            public void leftClick() {
                finish();
            }

            @Override
            public void rightClick() {

            }
        });

        getlist();
    }

    private void getlist(){
        apiDataRepository.htlist(null, new ApiNetResponse<List<HtBean>>() {
            @Override
            public void onSuccess(List<HtBean> data) {

                htAdapter = new HtAdapter(getContext(),data);
                listView.setAdapter(htAdapter);
                listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                        Intent intent = new Intent(getContext(),HtDetilActivity.class);
                        intent.putExtra("title",data.get(i).contract_title);
                        intent.putExtra("url",data.get(i).contract);
                        startActivity(intent);
                    }
                });
            }
        });
    }
}
